const express = require('express');
const router = express.Router();
const service = require("./service");
const jwt = require("../../plugins/jwt");
router.use(jwt);
router.use(function (err,req,res,next) {
    if(err){
        console.log(err);
    }
    if(err.name === "UnauthorizedError"){
        //这个需要根据自己的业务逻辑来处理（具体err值 请看下面）
        res.send({
            state:{
                "type":"error",
                "msg":"操作失败"
            },
            code:401
        });
    }
});
const multer = require("multer");//上传中间件
//const MAO =require("multer-aliyun-oss");
//上传到阿里云
/*const upload = multer({
    storage: MAO({
        config: {
            region: '<region>',
            accessKeyId: '<accessKeyId>',
            accessKeySecret: '<accessKeySecret>',
            bucket: '<bucket>'
        }
    })
});*/
const upload = multer({dest:__dirname+"/../../uploads"});//上传本地
//图片上传
router.post("/uploads",upload.single("file"),service.upload);
/**
 * 用户
 */
//用户注册
router.post("/webadmin/registered",service.registered);
//用户登录
router.post("/webadmin/login",service.login);
//用户信息
router.post("/webadmin/getuser",service.getUser);
router.post('/webadmin/getusernumbering', service.getUserNumbering)
//更新用户信息
router.post("/webadmin/updateuser",service.updateUser);
/**
 * 求助
 */
//创建求助
router.post('/webadmin/createhelp', service.createHelp);
//用户u获取求助列表
router.post('/webadmin/gethelplist', service.getHelpList);
//求助详情
router.post('/webadmin/gethelpdetails', service.getHelpDetails);
//修改求助
router.post('/webadmin/updatehelp', service.updateHelp);
//删除求助
router.post('/webadmin/deletehelp', service.deleteHelp);
/**
 * 活动
 */
//创建活动
router.post('/webadmin/createactivity', service.createActivity);
//用户u获活动列表
router.post('/webadmin/getactivitylist', service.getActivityList);
//活动详情
router.post('/webadmin/getactivitydetails', service.getActivityDetails);
//修改活动
router.post('/webadmin/updateactivity', service.updateActivity);
//删除活动
router.post('/webadmin/deleteactivity', service.deleteActivity);
//被joins列表
router.post('/webadmin/getjoinslist', service.getJoinsList);
//joins列表
router.post('/webadmin/joinslist', service.joinsList);
//删除join
router.post('/webadmin/deletejoin', service.deleteJoin);
/**
 * 二手
 */
//添加二手信息
router.post('/webadmin/createoldstuff', service.createOldStuff);
//获取二手列表
router.post('/webadmin/getoldstufflist', service.getOldStuffList);
//获取二手详情
router.post('/webadmin/getoldstuffdetails', service.getOldStuffDetails);
//修改二手信息
router.post('/webadmin/updateoldstuff', service.updateOldStuff);
//删除二手信息
router.post('/webadmin/deleteoldstuff', service.deleteOldStuff);
/**
 * 公司
 */
//获取个人公司详情
router.post('/webadmin/getcompany', service.getCompany);
//修改公司信息
router.post('/webadmin/changecompany', service.changeCompany);
//添加岗位
router.post('/webadmin/createjob', service.createJob);
//删除工作
router.post('/webadmin/deletejob', service.deleteJob);
/**
 * 文章
 */
//添加文章
router.post('/webadmin/createarticle', service.createArticle);
//文章列表
router.post('/webadmin/getarticlelist', service.getArticleList);
//文章详情
router.post('/webadmin/getarticledetails', service.getArticleDetails);
//修改文章
router.post('/webadmin/updatearticle', service.updateArticle);
//删除文章
router.post('/webadmin/deletearticle', service.deleteArticle);
/**
 * 其它
 */
//添加反馈
router.post('/webadmin/createfeedback', service.createFeedback);
//添加申诉
router.post('/webadmin/createappeal', service.createAppeal);
//添加举报
router.post('/webadmin/createreport', service.createReport);
//举报详情
router.post('/webadmin/getreportcontent', service.getReportContent);


module.exports = router;
